<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>capitalize(首字母大写转换器)</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
        }

        h1 {
            text-align: center;
        }

        .container {
            width: 100%;
            max-width: 600px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        label {
            font-weight: bold;
            display: block;
            margin-bottom: 10px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }

        button {
            padding: 10px 15px;
            font-size: 16px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        .result {
            margin-top: 20px;
            font-size: 18px;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>首字母大写转换器</h1>
        <label for="inputText">请输入文本:</label>
        <input type="text" id="inputText" placeholder="例如: fooBar">

        <label for="lowerRest">是否将其余字母转为小写?</label>
        <input type="checkbox" id="lowerRest" />

        <button type="button" id="covertBtn">转换</button>

        <div class="result" id="result"></div>
    </div>

    <script>
        // capitalize函数的实现
        const capitalize = ([first, ...rest], lowerRest = false) =>
            first.toUpperCase() +
            (lowerRest ? rest.join('').toLowerCase() : rest.join(''));

        // 处理用户输入并显示转换结果

        document.getElementById('covertBtn').onclick = function convertText() {
            const inputText = document.getElementById('inputText').value;
            const lowerRest = document.getElementById('lowerRest').checked;
            const result = capitalize(inputText, lowerRest);
            document.getElementById('result').textContent = `转换后的文本: ${result}`;
        }
    </script>
</body>

</html>